package moxl.factory;

import moxl.dom.MoxlElement;
import moxl.dom.XmlNamespace;
import moxl.dom.XmlNamespaceContext;
import moxl.dom.raw.RawBackedElement;
import moxl.parser.ParserException;
import moxl.parser.XmlParser;
import moxl.parser.resource.ClassResourceStreamXmlResource;
import moxl.raw.XmlResource;
import moxl.raw.XmlResourceException;
import moxl.tokenizer.TokenizerException;

public class DocumentFactory
{
	private final XmlParser parser = new XmlParser();

	public MoxlElement parseString(String xml, XmlNamespace ns) throws ParserException, TokenizerException, XmlResourceException
	{
		return new RawBackedElement(parser.parseString(xml), new XmlNamespaceContext(ns));
	}

	public MoxlElement parseResource(Class<? extends Object> anchor, String path) throws ParserException, TokenizerException, XmlResourceException
	{
		XmlResource resource = new ClassResourceStreamXmlResource(anchor, path);
		return new RawBackedElement(parser.parse(resource));
	}
}
